<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="name" @keyup.enter="SearchName">
    <TabBle :records="records" :name="name"></TabBle>
  </div>
</template>
<script>
import TabBle from './components/TabBle.vue';
export default {
  components: {
    TabBle,
  },
  data() {
    return {
      name: '',
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        }
      ]
    }
  },
  methods: {
    SearchName(value) {
      if (this.name.trim() === '') return alert('不能为空')
      this.name = value.target.value
      this.records = this.records.filter(item => item.doctor === this.name)
    }
  }
}
</script>

<style scoped></style>
